import apiEmp from "@/pages/v1/erp/Emp/js/apiEmp";
import design_point_func from "@/pages/v1/flow/Flow/ds/design_point_func";

export default () => {
    return {
        points: [],
        dictType:{
            "":"NA",
            START:"初始节点",
            COMM:"过程节点",
            END:"终止节点",
        },
        dictCondition:{
            "":"NA",
            PASS:"通过",
            BACK:"驳回",
            CANCEL:"中止",
        },
        init() {

        },
        addNewPoint() {
            let point = {
                name: "节点名称_" + this.points.length,
                key: this.createRandomString(16),
                type:"COMM",
                lock:true,

                next: [],
                //prev: [],
                auth:{//权限
                    user:[],
                    searchUserName:"",
                    apiResultUser:[],


                    department: [],
                    searchDepartmentName:"",
                    apiResultDepartment:[],
                },
                form:[],
                ...design_point_func
            }
            this.points.push(point)
        },
        //创建一个长度为N的随机字符串
        createRandomString(N) {
            let str = "";
            for (let i = 0; i < N; i++) {
                str += Math.floor(Math.random() * 10);
            }
            return str
        },
        getPointByKey(key) {
            if (key == ""){
                return {
                    name:"NA"
                }
            }
            for (let i = 0; i < this.points.length; i++) {
                if (this.points[i].key == key) {
                    return this.points[i]
                }
            }
        },
        createEmptySlot() {
            let slot = {
                key: "",
                condition: "",
                isDefault: false,
                note: "",
            }
            return slot
        },
        createEmptyFormItem(){
            let item = {
                key:"",
                name:"",
                type:"TEXT",
            }
            return item
        },
        deletePoint(key) {
            for (let i = 0; i < this.points.length; i++) {
                if (this.points[i].key == key) {
                    this.points.splice(i, 1)
                }
            }
        },
    }
}